package socket.InetAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * @description: 了解InetAddress类的用法
 * @author: Fesine
 * @createTime:2016/9/29 20:31
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/9/29 20:31
 */
public class TestInetAddress {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();//获取本主机对象
        System.out.println(address.getHostAddress());//获取ip地址
        System.out.println(address.getHostName());//获取主机名
        System.out.println(address);

        InetAddress address1 =InetAddress.getByName("192.168.138.1");
        System.out.println(address1.getHostName());
        InetAddress address2 = InetAddress.getByName("DESKTOP-PVBNJSA");
        System.out.println(address2.getHostAddress());

        byte[] bytes = address.getAddress();
        System.out.println(Arrays.toString(bytes));
    }
}
